package com.ticket.controller.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ticket.service.IMatchService;
import com.ticket.utils.Result;
import com.ticket.vo.MatchDetailVO;
import com.ticket.vo.MatchListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/matches")
public class MatchController {

    @Autowired
    private IMatchService matchService;
    
    @GetMapping("/list")
    public Result<Page<MatchListVO>> getMatchList(
            @RequestParam(value = "status", required = false) String status,
            @RequestParam(value = "teamId", required = false) Long teamId,
            @RequestParam(value = "page", defaultValue = "1") int page,
            @RequestParam(value = "size", defaultValue = "10") int size) {
        
        Page<MatchListVO> matchPage = matchService.getMatchList(status, teamId, page, size);
        return Result.success(matchPage);
    }
    
    @GetMapping("/{id}")
    public Result<MatchDetailVO> getMatchDetail(@PathVariable Long id) {
        MatchDetailVO matchDetail = matchService.getMatchDetail(id);
        if (matchDetail == null) {
            return Result.error("比赛不存在");
        }
        return Result.success(matchDetail);
    }
} 